﻿using System.Windows.Forms;
using UtfprLibrary.Windows.Forms.ComponentModel;

namespace UtfprLibrary.Windows.Forms {
    /// <summary>
    /// TODO
    /// </summary>
    public class UtfprConfiguration : IUtfprConfiguration {
        #region IUtfprConfiguration

        /// <summary>
        /// TODO
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IUtfprConfiguration SetFormSplash<T>() where T : UtfprFormSplashBase {
            UtfprApplication.Instance.SetFormSplashDefault<T>();
            return this;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IUtfprConfiguration SetFormLogin<T>() where T : UtfprFormLoginBase {
            UtfprApplication.Instance.SetFormLoginDefault<T>();
            return this;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IUtfprConfiguration SetFormMain<T>() where T : UtfprFormMainBase {
            UtfprApplication.Instance.SetFormMainDefault<T>();
            return this;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IUtfprConfiguration SetUtfprBindingNavigatorIcons<T>() where T : UtfprBindingNavigatorBaseIcons {
            UtfprApplication.Instance.SetUtfprBindingNavigatorIconsDefault<T>();
            return this;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <returns></returns>
        public IUtfprConfiguration DisableLogin() {
            UtfprApplication.Instance._isLoginEnabled = false;
            return this;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <returns></returns>
        public IUtfprConfiguration DisableSplash() {
            UtfprApplication.Instance._isSplashEnabled = false;
            return this;
        }

        /// <summary>
        /// TODO
        /// </summary>
        /// <returns></returns>
        public IUtfprConfiguration IsInDebugMode() {
            UtfprApplication.Instance._isInDebugMode = true;
            return this;
        }

        #endregion

        /// <summary>
        /// TODO
        /// </summary>
        public static UtfprFormSplashBase FormSplashDefault {
            get { return UtfprApplication.Instance.FormSplashDefault; }
        }

        /// <summary>
        /// TODO
        /// </summary>
        public static UtfprFormLoginBase FormLoginDefault {
            get { return UtfprApplication.Instance.FormLoginDefault; }
        }

        /// <summary>
        /// TODO
        /// </summary>
        public static UtfprFormMainBase FormMainDefault {
            get { return UtfprApplication.Instance.FormMainDefault; }
        }

        #region Singleton

        /// <summary>
        /// TODO
        /// </summary>
        private UtfprConfiguration() { }

        private static UtfprConfiguration _utfprConfiguration;
        /// <summary>
        /// TODO
        /// </summary>
        public static IUtfprConfiguration Instance {
            get {
                if (_utfprConfiguration == null) {
                    // Set the unhandled exception mode to force all Windows Forms errors to go through our handler.
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                    
                    _utfprConfiguration = new UtfprConfiguration();
                }

                return _utfprConfiguration;
            }
        }

        #endregion
    }
}
